package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanhua.dubbo.mappers.SettingsMapper;
import lombok.extern.slf4j.Slf4j;
import model.domain.Settings;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
@Slf4j
public class SettingsApiImpl implements SettingsApi {
    @Autowired
    private SettingsMapper settingsMapper;

    @Override
    public Settings findByUserId(Long userId) {
        log.info("findByUserId:"+String.valueOf(userId));
        LambdaQueryWrapper<Settings> settingsLambdaQueryWrapper = new LambdaQueryWrapper<>();
        settingsLambdaQueryWrapper.eq(Settings::getUserId, userId);
        return settingsMapper.selectOne(settingsLambdaQueryWrapper);
    }

    @Override
    public void update(Settings settings) {
        log.info("update:"+String.valueOf(settings));
        settingsMapper.updateById(settings);

    }

    @Override
    public void save(Settings settings) {
        log.info("save:"+String.valueOf(settings));
        settingsMapper.insert(settings);
    }

}
